<script setup>
import HomePanel from './HomePanel.vue'
import { getNewFlower } from '@/api/home.js'
import { ref } from 'vue'

const hotList = ref([])
const getHotList = async () => {
  const res = await getNewFlower()
  hotList.value = res.data
}
getHotList()
</script>

<template>
<HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
  <ul class="goods-list">
    <li v-for="item in hotList" :key="item.flowerId">
      <RouterLink :to="`/detail/${item.flowerId}`">
        <img :src="item.imageUrl" alt="flower" />
        <p class="name">{{ item.name }}</p>
        <p class="desc">{{ item.description }}</p>
      </RouterLink>
    </li>
  </ul>
</HomePanel>
</template>

<style scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 100%;
  margin: 0 auto;
  padding: 10px 0;
  list-style: none;
  padding-left: 0;
}

li {
  width: 250px;
  height: 420px;
  background-color: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  margin-bottom: 24px;
  
  &:hover {
    transform: translateY(-6px);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
  }
}

li img {
  width: 100%;
  height: 280px;
  object-fit: cover;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

li .name {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 12px 0 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 10px;
}

li .desc {
  font-size: 14px;
  color: #888;
  text-align: center;
  padding: 0 10px;
  line-height: 1.4;
  max-height: 3.6em;
  overflow: hidden;
  text-overflow: ellipsis;
}
a {
  text-decoration: none;
  color: inherit;
}

</style>
